#include "StdAfx.h"
#include "SerialCheck.h"
#include "SerialSingleton.h"
#include "../tinyxml/tinyxml.h"
#include "../macro.h"

SerialCheck::SerialCheck(void)
{
}

SerialCheck::~SerialCheck(void)
{
}

bool SerialCheck::run(void* param)
{
	DBG_PRINTF("%s\r\n",__FUNCTION__);

	SerialSingleton& serial = SerialSingleton::getInstance();

	TiXmlDocument doc;
	if (!doc.LoadFile("./config.xml"))
	{
		return false;
	}

	TiXmlElement* pRoot = doc.RootElement();
	if (!pRoot)
	{
		return false;
	}

	// Get test case
	TiXmlNode* pNode = pRoot->FirstChild("com");
	if (!pNode)
	{
		ERR_PRINTF("config file error, no com num");
		return false;
	}

	const char* pComNum = pNode->ToElement()->GetText();
	if (pComNum==NULL)
	{
		ERR_PRINTF("config file error, com num error");
		return false;

	}


	return serial.open(pComNum);
}